package com.tobby.camel.camelinaction.chapter2.wiretap;

import javax.jms.ConnectionFactory;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jms.JmsComponent;
import org.apache.camel.impl.DefaultCamelContext;

public class OrderRouterWithWireTap {

	public static void main(String[] args) throws Exception {
		CamelContext context = new DefaultCamelContext();
		ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
				"vm://localhost");
		context.addComponent("jms",
				JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));

		context.addRoutes(new RouteBuilder() {

			@Override
			public void configure() throws Exception {
				from("file:src/main/resources/data?noop=true").wireTap("jms:orderAudit");

				from("jms:orderAudit").process(new Processor() {

					@Override
					public void process(Exchange exchange) throws Exception {
						System.out.println("Received Order : "
								+ exchange.getIn().getHeader("CamelFileName"));
					}
				});
			}
		});
		context.start();
		Thread.sleep(10000);
		context.stop();
	}

}
